package com.bifrost.entity;

import java.io.Serializable;
import javax.persistence.*;
import java.util.List;


/**
 * The persistent class for the CATEGORY database table.
 */
@Entity
@Table(name = "CATEGORY",indexes = {
        @Index(name = "IS_PARENT_INDEX",columnList = "IS_PARENT",unique = false)
})
@NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c")
public class Category extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CATEGORY_ID", unique = true, nullable = false)
    private Long categoryId;

    @Column(name = "CATEGORY_CODE", length = 100)
    private String categoryCode;

    @Column(name = "CATEGORY_DEPTH")
    private int categoryDepth;

    @Column(name = "CATEGORY_DESCRIPTION", length = 255)
    private String categoryDescription;

    @Column(name = "CATEGORY_LINEAGE", length = 255)
    private String categoryLineage;

    @Column(name = "CATEGORY_NAME", nullable = false, length = 100)
    private String categoryName;

    @Column(name = "CATEGORY_STATUS", length = 100)
    private String categoryStatus;

    @Column(name = "DISPLAY_TEMPLATE", length = 100)
    private String displayTemplate;

    @Column(name = "EXTERNAL_ID", length = 100)
    private String externalId;

    @Column(name = "FULFILLMENT_TYPE", length = 100)
    private String fulfillmentType;

    @Column(name = "INVENTORY_TYPE", length = 100)
    private String inventoryType;

    @Column(name = "IS_ARCHIVED")
    private Boolean isArchived = Boolean.FALSE;

    @Column(name = "IS_VISIBLE")
    private Boolean isVisible = Boolean.TRUE;

    @Column(name = "META_DESC", length = 255)
    private String metaDesc;

    @Column(name = "META_TITLE", length = 255)
    private String metaTitle;

    @Column(name = "PARENT_ID", nullable = false)
    private Long parentId;

    @Column(name = "IS_PARENT", nullable = false)
    private Boolean isParent = Boolean.FALSE;

    @Column(name = "SORT_ORDER")
    private Integer sortOrder = 0;

    @Column(name = "BONUS_POINTS_RATE", precision = 11)
    private Integer bonusPointsRate;


    //bi-directional many-to-one association to Media
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MEDIA_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Media media;

    //bi-directional many-to-one association to MerchantStore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MERCHANT_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private MerchantStore merchantStore;

    //bi-directional many-to-one association to CategoryAttribute
    @OneToMany(mappedBy = "category")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<CategoryAttribute> categoryAttributes;

    //bi-directional many-to-one association to Product
    @OneToMany(mappedBy = "productCategory")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<Product> products;

    @OneToMany(mappedBy = "category")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<ProductSku> skus;

    public Category() {
    }

    public Long getCategoryId() {
        return this.categoryId;
    }

    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategoryCode() {
        return this.categoryCode;
    }

    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }

    public int getCategoryDepth() {
        return this.categoryDepth;
    }

    public void setCategoryDepth(int categoryDepth) {
        this.categoryDepth = categoryDepth;
    }

    public String getCategoryDescription() {
        return this.categoryDescription;
    }

    public void setCategoryDescription(String categoryDescription) {
        this.categoryDescription = categoryDescription;
    }

    public String getCategoryLineage() {
        return this.categoryLineage;
    }

    public void setCategoryLineage(String categoryLineage) {
        this.categoryLineage = categoryLineage;
    }

    public String getCategoryName() {
        return this.categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public String getCategoryStatus() {
        return this.categoryStatus;
    }

    public void setCategoryStatus(String categoryStatus) {
        this.categoryStatus = categoryStatus;
    }

    public String getDisplayTemplate() {
        return this.displayTemplate;
    }

    public void setDisplayTemplate(String displayTemplate) {
        this.displayTemplate = displayTemplate;
    }

    public String getExternalId() {
        return this.externalId;
    }

    public void setExternalId(String externalId) {
        this.externalId = externalId;
    }

    public String getFulfillmentType() {
        return this.fulfillmentType;
    }

    public void setFulfillmentType(String fulfillmentType) {
        this.fulfillmentType = fulfillmentType;
    }

    public String getInventoryType() {
        return this.inventoryType;
    }

    public void setInventoryType(String inventoryType) {
        this.inventoryType = inventoryType;
    }

    public Boolean getIsArchived() {
        return this.isArchived;
    }

    public void setIsArchived(Boolean isArchived) {
        this.isArchived = isArchived;
    }

    public Boolean getIsVisible() {
        return this.isVisible;
    }

    public void setIsVisible(Boolean isVisible) {
        this.isVisible = isVisible;
    }

    public String getMetaDesc() {
        return this.metaDesc;
    }

    public void setMetaDesc(String metaDesc) {
        this.metaDesc = metaDesc;
    }

    public String getMetaTitle() {
        return this.metaTitle;
    }

    public void setMetaTitle(String metaTitle) {
        this.metaTitle = metaTitle;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Boolean isParent() {
        return isParent;
    }

    public void setParent(Boolean parent) {
        isParent = parent;
    }

    public Integer getSortOrder() {
        return this.sortOrder;
    }

    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }

    public Integer getBonusPointsRate() {
        return bonusPointsRate;
    }

    public void setBonusPointsRate(Integer bonusPointsRate) {
        this.bonusPointsRate = bonusPointsRate;
    }

    public Media getMedia() {
        return this.media;
    }

    public void setMedia(Media media) {
        this.media = media;
    }

    public MerchantStore getMerchantStore() {
        return this.merchantStore;
    }

    public void setMerchantStore(MerchantStore merchantStore) {
        this.merchantStore = merchantStore;
    }

    public List<CategoryAttribute> getCategoryAttributes() {
        return this.categoryAttributes;
    }

    public void setCategoryAttributes(List<CategoryAttribute> categoryAttributes) {
        this.categoryAttributes = categoryAttributes;
    }

    public CategoryAttribute addCategoryAttribute(CategoryAttribute categoryAttribute) {
        getCategoryAttributes().add(categoryAttribute);
        categoryAttribute.setCategory(this);

        return categoryAttribute;
    }

    public CategoryAttribute removeCategoryAttribute(CategoryAttribute categoryAttribute) {
        getCategoryAttributes().remove(categoryAttribute);
        categoryAttribute.setCategory(null);

        return categoryAttribute;
    }

    public List<Product> getProductCategories() {
        return this.products;
    }

    public void setProductCategories(List<Product> products) {
        this.products = products;
    }

    public Product addProduct(Product product) {
        getProductCategories().add(product);
        product.setProductCategory(this);

        return product;
    }

    public Product removeProduct(Product product) {
        getProductCategories().remove(product);
        product.setProductCategory(null);

        return product;
    }

    public List<ProductSku> getSkus() {
        return skus;
    }

    public void setSkus(List<ProductSku> skus) {
        this.skus = skus;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Category category = (Category) o;

        if (getCategoryDepth() != category.getCategoryDepth()) return false;
        if (!getCategoryId().equals(category.getCategoryId())) return false;
        if (getCategoryCode() != null ? !getCategoryCode().equals(category.getCategoryCode()) : category.getCategoryCode() != null)
            return false;
        return getCategoryName().equals(category.getCategoryName());
    }

    @Override
    public int hashCode() {
        int result = getCategoryId().hashCode();
        result = 31 * result + (getCategoryCode() != null ? getCategoryCode().hashCode() : 0);
        result = 31 * result + getCategoryDepth();
        result = 31 * result + getCategoryName().hashCode();
        return result;
    }
}